<script setup lang='ts'>
  import { nextTick, reactive, ref } from 'vue';
  import { statisticsApi } from '@/api/controller';
  import serachUserid from '@/components/serachUserid/index.vue';
  import { ToastSuccess, Toastloading } from '@/utils/public';
  const formLabelWidth = '120px'
  const dataForm = ref()
  const $emit = defineEmits(['updateList'])
  const action = reactive({
    dialogFormVisible:false,
    disabled:false,
    title:'',
  })
  interface formQuert {
    remind:string
    id:number
    b_status:number
  }
  let form = reactive({} as formQuert)
  const handleSubmit = ()=>{
    dataForm.value.validate(async(valid:any)=>{
      if(!valid) return
      const loading = Toastloading()
      await statisticsApi.sdj2023LybAudit(form).then(()=>{
        loading.close()
        $emit('updateList')
        closeDialog()
        ToastSuccess('审核成功')
      })
    })
  }
  const openDialog = (query:any = {})=> {
    const { 
      id,
      b_status
    } = query
    Object.assign(form,{
      id,
      b_status,
      remind:''
    })
    action.title = `${b_status==1?'通过':'驳回'}留言审核`
    action.dialogFormVisible = true
  }
  const closeDialog = ()=>{
    form = reactive({} as formQuert)
    nextTick(() => {
      dataForm.value.clearValidate();
    });
    action.dialogFormVisible = false
  }
  defineExpose({
    openDialog
  })
</script>

<template>
  <div>
    <el-dialog
    top="5vh"
    class="xm-dialog input-width"
    v-model="action.dialogFormVisible"
    :close-on-click-modal="action.disabled"
    :show-close="action.disabled"
    :close-on-press-escape="action.disabled"
    width="40%"
    :title="action.title">
      <el-form ref="dataForm" :model="form">
        <el-form-item :label-width="formLabelWidth" label="审核备注">
          <el-input
            :disabled="action.disabled"
            v-model="form.remind"
            :autosize="{ minRows: 6, maxRows: 6}"
            type="textarea"
            placeholder="请填审核备注"
          />
        </el-form-item>
      </el-form>
      <template v-if="!action.disabled" #footer>
        <span class="dialog-footer">
          <el-button @click="closeDialog">取 消</el-button>
          <el-button type="primary" @click="handleSubmit()">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>